package gui.Main;

import communications.Command;
import communications.GlobalObjectId;
import communications.ObjectDB;
import communications.PeerCommunicator;
import java.io.ObjectStreamException;
import java.io.Serializable;

public class GUIObserverProxy
    extends GUIObserver
    implements Serializable
{
    private GlobalObjectId globalObjectId;

    public GUIObserverProxy(GlobalObjectId globalObjectId){
    	super();
        this.globalObjectId = globalObjectId;
    }

	@Override
    public void nodeAddedToHyPeerWeb(hypeerweb.HyPeerWeb p0, hypeerweb.Node p1){
        String[] parameterTypeNames = new String[2];
        parameterTypeNames[0] = "hypeerweb.HyPeerWeb";
        parameterTypeNames[1] = "hypeerweb.Node";
        Object[] actualParameters = new Object[2];
        actualParameters[0] = p0;
        actualParameters[1] = p1;
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUIObserver", "nodeAddedToHyPeerWeb", parameterTypeNames, actualParameters, false);
        PeerCommunicator.getSingleton().sendASynchronous(globalObjectId, command);
    }

	@Override
    public void nodeRemovedFromHyPeerWeb(hypeerweb.HyPeerWeb p0, hypeerweb.Node deadNode){
        String[] parameterTypeNames = new String[2];
        parameterTypeNames[0] = "hypeerweb.HyPeerWeb";
        parameterTypeNames[1] = "hypeerweb.Node";
        Object[] actualParameters = new Object[2];
        actualParameters[0] = p0;
        actualParameters[1] = deadNode;
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUIObserver", "nodeRemovedFromHyPeerWeb", parameterTypeNames, actualParameters, false);
        PeerCommunicator.getSingleton().sendASynchronous(globalObjectId, command);
    }

	@Override
    public void clearHypeerweb(){
        String[] parameterTypeNames = new String[0];
        Object[] actualParameters = new Object[0];
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUIObserver", "clearHypeerweb", parameterTypeNames, actualParameters, false);
        PeerCommunicator.getSingleton().sendASynchronous(globalObjectId, command);
    }

	@Override
    public void hibernateHyPeerWeb(){
        String[] parameterTypeNames = new String[0];
        Object[] actualParameters = new Object[0];
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUIObserver", "hibernateHyPeerWeb", parameterTypeNames, actualParameters, false);
        PeerCommunicator.getSingleton().sendASynchronous(globalObjectId, command);
    }

	@Override
    public void segmentDisconnect(hypeerweb.HyPeerWeb p0, hypeerweb.HyPeerWeb p1){
        String[] parameterTypeNames = new String[2];
        parameterTypeNames[0] = "hypeerweb.HyPeerWeb";
        parameterTypeNames[1] = "hypeerweb.HyPeerWeb";
        Object[] actualParameters = new Object[2];
        actualParameters[0] = p0;
        actualParameters[1] = p1;
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUIObserver", "segmentDisconnect", parameterTypeNames, actualParameters, false);
        PeerCommunicator.getSingleton().sendASynchronous(globalObjectId, command);
    }

	@Override
    public communications.LocalObjectId getLocalObjectId(){
        String[] parameterTypeNames = new String[0];
        Object[] actualParameters = new Object[0];
        Command command = new Command(globalObjectId.getLocalObjectId(), "gui.Main.GUIObserver", "getLocalObjectId", parameterTypeNames, actualParameters, true);
        Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
        return (communications.LocalObjectId)result;
    }

	@Override
    public boolean equals(java.lang.Object p0){
    	if (p0 instanceof GUIObserverProxy)
    	{
    		GUIObserverProxy otherProxy = (GUIObserverProxy)p0;
    		
    		return globalObjectId.equals(otherProxy.globalObjectId);
    	}
    	
    	return false;
    }

	@Override
    public java.lang.String toString(){
        String[] parameterTypeNames = new String[0];
        Object[] actualParameters = new Object[0];
        Command command = new Command(globalObjectId.getLocalObjectId(), "java.lang.Object", "toString", parameterTypeNames, actualParameters, true);
        Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
        return (java.lang.String)result;
    }

	@Override
    public int hashCode(){
        String[] parameterTypeNames = new String[0];
        Object[] actualParameters = new Object[0];
        Command command = new Command(globalObjectId.getLocalObjectId(), "java.lang.Object", "hashCode", parameterTypeNames, actualParameters, true);
        Object result = PeerCommunicator.getSingleton().sendSynchronous(globalObjectId, command);
        return (Integer)result;
    }

	@Override
	public Object writeReplace() throws ObjectStreamException
	{
		return new GUIObserverProxy(globalObjectId);
	}
	
	public Object readResolve() throws ObjectStreamException
	{
		if (globalObjectId.onCurrentMachine())
		{
			return ObjectDB.getSingleton().getValue(globalObjectId.getLocalObjectId());	
		}
		else
		{
			return this;
		}
	}
}
